package cn.edu.sgu.www.mhxysy.controller.xingyin;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.xingyin.XingyinTexiaoDTO;
import cn.edu.sgu.www.mhxysy.vo.treegrid.XingyinTexiaoTreeGrid;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.xingyin.XingyinTexiaoService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "星印特效管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/xingyin_texiao", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class XingyinTexiaoController {

    private final XingyinTexiaoService xingyinTexiaoService;

    @Autowired
    public XingyinTexiaoController(XingyinTexiaoService xingyinTexiaoService) {
        this.xingyinTexiaoService = xingyinTexiaoService;
    }

    @ApiOperation("为星印分配特效")
    @RequestMapping(value = "/distribute", method = RequestMethod.POST)
    public JsonResult<Void> distribute(@Validated XingyinTexiaoDTO texiaoDTO) {
        xingyinTexiaoService.distribute(texiaoDTO);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("删除星印特效")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "texiaoId", value = "星印特效类型ID", required = true),
            @ApiImplicitParam(name = "xingyinId", value = "星印类型ID", required = true)
    })
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JsonResult<Void> delete(
            @NotNull(message = "星印特效类型" + CustomMessages.ID_NOT_NULL) Integer texiaoId,
            @NotNull(message = "星印类型" + CustomMessages.ID_NOT_NULL) Integer xingyinId) {
        xingyinTexiaoService.delete(texiaoId, xingyinId);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("查询星印特效菜单树")
    @RequestMapping(value = "/listTree", method = RequestMethod.GET)
    public JsonResult<List<XingyinTexiaoTreeGrid>> listTree(
            @ApiParam(name = "xingyinId", value = "星印类型ID", required = false)
            @RequestParam(required = false) Integer xingyinId) {
        List<XingyinTexiaoTreeGrid> list = xingyinTexiaoService.listTree(xingyinId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("查询星印特效类型ID列表")
    @RequestMapping(value = "/selectTexiaoIds", method = RequestMethod.GET)
    public JsonResult<List<Integer>> selectTexiaoIds(
            @ApiParam(name = "xingyinId", value = "星印类型ID", required = true)
            @NotNull(message = "星印类型" + CustomMessages.ID_NOT_NULL) Integer xingyinId) {
        List<Integer> list = xingyinTexiaoService.selectTexiaoIds(xingyinId);

        return JsonResult.success(null, list);
    }

}